package com.uetoken.cn.utils;

import java.text.DecimalFormat;

public class Save2DecimalUtils {
    /**
     * 获取double数据小数点后两位不进行四舍五入
     * @param value
     * @return 0 , String
     *     
     */
    public static String getDecimalPrecision(String value, int newScale) {
        String result = "0";
        String intVal;
        String decimalsVal = "";
        String[] arr = value.split("\\.");
        intVal = arr[0];
        if (arr.length == 2) {
            decimalsVal = arr[1];
        }
        if (decimalsVal.length() == newScale) {
            result = intVal + "." + decimalsVal;
        } else if (decimalsVal.length() > newScale) {
            result = intVal + "." + decimalsVal.substring(0, newScale);
        } else {
            String repair = "";
            for (int i = 0; i < newScale; i++) {
                if (i >= decimalsVal.length()) {
                    repair = repair + "0";
                }
            }
            result = intVal + "." + decimalsVal + repair;
        }


        return result;
    }
}
